﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
//using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using PaintDotNet.Typography;
using PaintDotNet.Rendering;
using PaintDotNet.VisualStyling;
using PaintDotNet.Threading;
using PaintDotNet.IndirectUI;
using PaintDotNet.Controls;
using PaintDotNet.SystemLayer.Typography;
using System.Drawing;


namespace drawTxt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(250, 25);
            ////应该是相当于bitmap
            //PaintDotNet.Surface sf = new PaintDotNet.Surface(100, 100);

            TypographyService newTypographyService = new TypographyService();


            var font = newTypographyService.FromGdipFont(new System.Drawing.Font("方正卡通简体", 17));

            PaintDotNet.SystemLayer.Typography.Gdi.GdiTypographyDriver gdi =
                    new PaintDotNet.SystemLayer.Typography.Gdi.GdiTypographyDriver(newTypographyService);

            var fontRenderSetting = gdi.CreateFontRendererSettings(TextDisplayIntent.Other, TextRenderMode.Default);
            IFontRenderer frender = gdi.CreateFontRenderer(font, fontRenderSetting);
            IBitmapTextRenderTarget x = gdi.CreateBitmapRenderTarget(image);
            x.ForeColor = 0xC2272D;
            x.BackColor = 0x55FBEEB6;

            frender.DrawText(x, "韩梅梅思明区湖滨南路469号福联大饭店", new System.Windows.Point(0, 0), new System.Windows.Int32Rect(0, 0, 250, 25));

            e.Graphics.DrawImage(image, new System.Drawing.Point(0, 0));
           // image.MakeTransparent(toColor("#FBEEB6"));
            image.Save(@"c:\a.png");

        }
        private Color toColor(string str)
        {
            var r = str.Substring(1, 2);
            var g = str.Substring(3, 2);
            var b = str.Substring(5, 2);
            return Color.FromArgb(
                 Convert.ToInt32(r, 16),
                 Convert.ToInt32(g, 16),
                 Convert.ToInt32(b, 16));
        }
    }
}
